package com.testdemo.web.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.testdemo.web.dao.ResourceDao;
import com.testdemo.web.vo.LabResource;
@Service
public class ResourceServiceImpl implements ResourceService {

	@Autowired
	private ResourceDao resourceDao;
	
	@Override
	public int addResource(LabResource labResource) {
		return resourceDao.insertLabResource(labResource);
	}

	@Override
	public int deleteResource(LabResource labResource) {
		return resourceDao.deleteLabResource(labResource);
	}

	@Override
	public int applyResource(LabResource labResource) {
		return resourceDao.applyLabResource(labResource);
	}

	@Override
	public int getBackResource(LabResource labResource) {
		return resourceDao.getbackLabResource(labResource.getResourceid());
	}

	@Override
	public int checkApplyResource(LabResource labResource) {
		if(labResource.getIscheck().equals(0)) {
			return resourceDao.getbackLabResource(labResource.getResourceid());
		}else {
			Date date = new Date();
			labResource.setBorrowdate(date);
			return resourceDao.checkOutLabResource(labResource);
		}
	}

	@Override
	public List<LabResource> getUnusedResource(LabResource labResource) {
		return resourceDao.selectunusedResourcelist(labResource.getLabid());
	}

	@Override
	public List<LabResource> getApplyList(LabResource labResource) {
		return resourceDao.selectApplyResourceList(labResource.getLabid());
	}

	@Override
	public List<LabResource> getBorrowList(LabResource labResource) {
		return resourceDao.selectResourceBorrowList(labResource.getLabid());
	}

	@Override
	public List<LabResource> getBorrowListByUsername(String username) {
		return resourceDao.selectResourceBorrowListByUsername(username);
	}

}
